package com.webchat.ugc.messaegqueue.consumer.redis;

import com.webchat.common.enums.messagequeue.MessageQueueEnum;
import com.webchat.common.service.messagequeue.consumer.AbstractRedisDelayQueueConsumer;
import com.webchat.common.service.messagequeue.consumer.AbstractRedisQueueConsumer;
import com.webchat.common.service.messagequeue.producer.MessageQueueProducer;
import com.webchat.common.util.JsonUtil;
import com.webchat.domain.dto.queue.ChatAccountListMessageDTO;
import com.webchat.domain.dto.queue.MallOrderTimeoutMessageDTO;
import com.webchat.ugc.service.mall.im.MallChatAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;


@Service
public class MallChatAccountListRedisMQConsumer extends AbstractRedisQueueConsumer<ChatAccountListMessageDTO> {


    @Autowired
    private MallChatAccountService mallChatAccountService;

    @Override
    protected ChatAccountListMessageDTO convert(String s) {

        return JsonUtil.fromJson(s, ChatAccountListMessageDTO.class);
    }

    @Override
    protected MessageQueueEnum getMessageQueue() {

        return MessageQueueEnum.QUEUE_MALL_CHAT_ACCOUNT_LIST_MESSAGE;
    }

    @Override
    protected void receive(ChatAccountListMessageDTO data) {

        mallChatAccountService.doConsume(data);
    }

    @Override
    protected void error(ChatAccountListMessageDTO data, Exception ex) {

        // TODO
    }

    /**
     * 重写线程池核心线程数获取方法，并发消费（默认单线程消费）
     *
     * @return
     */
    @Override
    protected int getPoolSize() {
        // 单节点5个线程并发消费
        return 5;
    }
}
